package team.seekers.catering.user.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import team.seekers.catering.user.entity.dao.Building;
import team.seekers.catering.order.mapper.BuildingMapper;

import java.util.ArrayList;
import java.util.List;

/**
 * 楼栋信息
 * @author hbc
 * @since 2021-03-17
 */
@Service
public class BuildingService extends ServiceImpl<BuildingMapper, Building>{

    public String getByInfo(Integer park, Integer buildingNum) {
        QueryWrapper<Building> wrapper = new QueryWrapper<>();
        wrapper.eq("park",park);
        wrapper.eq("building",buildingNum);
        Building building = getOne(wrapper);
        if(building == null){
            return null;
        }
        return building.getId();
    }


    public List<String> listByInfo(Integer park, Integer buildingNum) {
        QueryWrapper<Building> wrapper = new QueryWrapper<>();
        if(park != null){
            wrapper.eq("park",park);
        }
        if(buildingNum != null){
            wrapper.eq("building",buildingNum);
        }
        List<Building> list = list(wrapper);
        List<String> idList = new ArrayList<>();
        for (Building building : list) {
            idList.add(building.getId());
        }
        return idList;
    }
}
